#include "widget.h"
#include "ui_widget.h"
#include <iostream>

widget::widget(QWidget *parent) :
    QGraphicsView(parent)
{
    scene = new QGraphicsScene(this);
}

widget::~widget()
{
    delete scene;
}

void widget::mousePressEvent(QMouseEvent* ev){
    scene->setSceneRect(0, 0, this->width(), this->height());
    setScene(scene);
    if (ev->button() == Qt::LeftButton){
        drowSquare(ev->pos());
    }
    else if (ev->button() == Qt::RightButton){
        drowCircle(ev->pos());
    }
}
void widget::drowSquare(const QPoint & pos){
     x = pos.x();
     y = pos.y();
     scene->addRect(x, y, 30, 30, QPen(Qt::red, 1, Qt::SolidLine));
}

void widget::drowCircle(const QPoint & pos){
    x = pos.x();
    y = pos.y();
    scene->addEllipse(x, y, 20, 20, QPen(Qt::blue, 1, Qt::SolidLine));
}
